<?php

/**
 * Compras form.
 *
 * @package    tercermilenio
 * @subpackage form
 * @author     Your name here
 */
class ConfiguracionForm extends sfForm {

    public function configure() {

        $pathConfig = sfConfig::get('sf_app_config_dir');
        $file = '/app.yml';
        try {
            $loader = sfYaml::load($pathConfig . $file);
        } catch (InvalidArgumentException $e) {
            // an error occurred during parsing
            echo "Unable to parse the YAML string: " . $e->getMessage();
        }

        /* *******************
         * ** DEFAULT VALUES ***
         * ******************* */
        $this->setDefault('iva',$loader['all']['iva']);
        $this->setDefault('descuento',$loader['all']['descuento']);
        $this->setDefault('caja_inicial',$loader['all']['caja_valor_inicial_diario']);
        //$this->setDefault('', '');


        /* *******************
         * *** SET LABEL *******
         * ******************* */
        $this->widgetSchema['iva']->setLabel('IVA (%)');
        $this->widgetSchema['descuento']->setLabel('Descuento (%)');
        $this->widgetSchema['caja_inicial']->setLabel('Caja Inicial Diaria');
    }

    public function setup() {
        parent::setup();

        /* *******************
         * ***  WIDGETS  *****
         * ***************** */
        $this->setWidget('iva', new sfWidgetFormInput());
        $this->setWidget('descuento', new sfWidgetFormInput());
        $this->setWidget('caja_inicial', new sfWidgetFormInput());


        /* *******************
         * *** VALIDATORS ****
         * ***************** */
        $this->setValidator('iva', new sfValidatorNumber());
        $this->setValidator('descuento', new sfValidatorNumber());
        $this->setValidator('caja_inicial', new sfValidatorNumber());



        $this->widgetSchema->setNameFormat('configuracion[%s]');
        $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
    }

}
